<template>
<h1>员工列表综合练习</h1>
  <el-form style="width: 600px;margin: 0 auto">
    <el-form-item label="姓名">
      <el-input v-model="user.username" placeholder="请输入姓名"></el-input>
    </el-form-item>

    <el-form-item label="工资">
      <el-input v-model="user.salary" placeholder="请输入工资"></el-input>
    </el-form-item>

    <el-form-item label="岗位">
      <el-input v-model="user.job" placeholder="请输入岗位"></el-input>
    </el-form-item>

    <el-form-item>
      <el-button type="success" @click="submit()">点我提交</el-button>
    </el-form-item>
  </el-form>

  <el-table :data="userArr">
    <el-table-column type="selection" width="80"></el-table-column>
    <el-table-column prop="username" label="姓名" align="center"></el-table-column>
    <el-table-column prop="salary" label="工资" align="center"></el-table-column>
    <el-table-column prop="job" label="工作" align="center"></el-table-column>

    <el-table-column label="操作" >
      <template #default="scope">
        <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
  <hr>
</template>

<script setup>
import {ref} from "vue";

const user =ref({
  username: '',
  salary: '',
  job: '',
})

const userArr = ref([])

const submit=()=>{
  userArr.value.push(user.value)
}

const del = (index, user)=>{
  if (confirm('确定删除' + user.username + '吗？')) {
    userArr.value.splice(index, 1)
  }
}
</script>

<style scoped>

</style>